# (C) Copyright 2016-2023 Intel Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
"""Unit tests"""

TEST_SRC = ['test_linkage.cpp', 'utest_hlc.c', 'utest_swim.c',
            'utest_portnumber.c', 'utest_protocol.c']
LIBPATH = [Dir('../../'), Dir('../../../gurt')]


def scons():
    """Scons function"""
    if GetOption('help'):
        return

    Import('env', 'cart_targets', 'swim_targets', 'gurt_targets')

    test_env = env.Clone()
    test_env.require('mercury', 'uuid', 'cmocka')
    # The test is checking that this feature works so disable the compile warnings for it.
    test_env.AppendIfSupported(CCFLAGS=['-Wno-gnu-designator', '-Wno-missing-field-initializers'])
    test_env.AppendUnique(LIBS=['pthread', 'm', 'yaml', 'dl'])
    test_env.AppendUnique(CXXFLAGS=['-std=c++0x'])
    test_env.AppendUnique(LIBPATH=LIBPATH)
    test_env.AppendUnique(RPATH_FULL=LIBPATH)

    for test in TEST_SRC:
        testprog = test_env.d_test_program(source=[test, cart_targets, swim_targets, gurt_targets])
        Default(testprog)


if __name__ == "SCons.Script":
    scons()
